#include <iostream>
#include <deque>

using namespace std;
const int N = 5e5 + 10;
int f[N];
int main()
{
	deque<int> dq;
	int n, m; cin >> n >> m;
	dq.push_front(0);
	int ret = -500;
	for (int i = 1; i <= n; i++)
	{
		int x; cin >> x;
		f[i] = f[i - 1] + x;
	}
	for (int i = 1; i <= n; i++)
	{
		ret = max(ret, f[i] - f[dq.front()]);
		while (dq.size() && f[dq.back()] >= f[i]) dq.pop_back();
		dq.push_back(i);
		if (dq.back() - dq.front() + 1 > m) dq.pop_front();
	}
	cout << ret << endl;
	return 0;
}